package com.gsmdata;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

/**
 * @author Administrator
 */
public class GsmDataCreateJob extends Configured implements Tool {

    public static void main(String[] args) throws Exception {
        int res = ToolRunner.run(new Configuration(), new GsmDataCreateJob(), args);
        System.exit(res);
    }

    @Override
    public int run(String[] args) throws Exception {

        Job job = Job.getInstance(getConf());
        Path outputDir = new Path(args[0]);

        FileOutputFormat.setOutputPath(job, outputDir);
        job.setJobName("GsmDataCreateJob");
        job.setJarByClass(GsmDataCreateJob.class);
        job.setMapperClass(GsmDataMap.class);

        // 设置reducer task 为0
        job.setNumReduceTasks(0);
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(Text.class);

        // 设置 GsmDataInputFormat
        job.setInputFormatClass(GsmDataInputFormat.class);

        // 传入相关参数
        job.getConfiguration().set("data.split_number", args[1]);
        job.getConfiguration().set("data.data_number", args[2]);

        return job.waitForCompletion(true) ? 0 : 1;
    }
}
